home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Pascal Strings / PString.cp < prev    next >
Text File  |  2000-06-23  |  3KB  |  134 lines

  1. // PString.cp
  2.  
  3. #ifndef PString_h
  4. #include "PString.h"
  5. #endif
  6.  
  7. PString::PString( Data theSpace )
  8.   : space( theSpace )
  9.   {
  10.     Assert( !space.Null() );
  11.     Assert( StorageLength() <= maxStorageLength );
  12.     Assert( Length() < StorageLength() );
  13.   }
  14.  
  15. PString::PString( Data theSpace, ConstStr255Param text )
  16.   : space( theSpace )
  17.   {
  18.     Assert( !space.Null() );
  19.     Assert( StorageLength() <= maxStorageLength );
  20.     Assert( text[0] < StorageLength() );
  21.     if ( text != space.Start() )
  22.         space << ConstData( text, text[0]+1 );
  23.   }
  24.  
  25. PString::PString( Data theSpace, ConstPString text )
  26.   : space( theSpace )
  27.   {
  28.     Assert( !space.Null() );
  29.     Assert( StorageLength() <= maxStorageLength );
  30.     Assert( text.Length() < StorageLength() );
  31.     space << ConstData( text, text.Length()+1 );
  32.   }
  33.  
  34. PString::PString( Data theSpace, PString text )
  35.   : space( theSpace )
  36.   {
  37.     Assert( !space.Null() );
  38.     Assert( StorageLength() <= maxStorageLength );
  39.     Assert( text.Length() < StorageLength() );
  40.     space << ConstData( text, text.Length()+1 );
  41.   }
  42.  
  43. PString::PString( Data theSpace, ConstData text )
  44.   : space( theSpace )
  45.   {
  46.     Assert( !space.Null() );
  47.     Assert( StorageLength() <= maxStorageLength );
  48.     Assert( text.Length() < StorageLength() );
  49.     space[0] = text.BoundedLength( StorageLength() );
  50.     TextSpace() << text;
  51.   }
  52.  
  53. void PString::Truncate( uint32 end )
  54.   {
  55.     if ( Length() > end )
  56.         space[0] = end;
  57.   }
  58.  
  59. void PString::SetLength( uint32 newLength )
  60.   {
  61.     Assert( newLength < StorageLength() );
  62.     space[0] = newLength;
  63.   }
  64.  
  65. void PString::operator=( ConstData text )
  66.   {
  67.     Assert( text.Length() < StorageLength() );
  68.     space[0] = text.BoundedLength( StorageLength() );
  69.     TextSpace() << text;
  70.   }
  71.  
  72. void PString::operator+=( uint8 c )
  73.   {
  74.     Assert( Length() + 1 < StorageLength() );
  75.     if ( Length() + 1 < StorageLength() )
  76.         space[ ++space[0] ] = c;
  77.   }
  78.  
  79. void PString::operator+=( ConstData text )
  80.   {
  81.     Assert( Length() + text.Length() < StorageLength() );
  82.     UnusedSpace() << text;
  83.     space[0] += text.BoundedLength( UnusedSpace().Length() );
  84.   }
  85.  
  86. void PString::Remove( URange32 range )
  87.   {
  88.     Assert( range.End() <= Length() );
  89.     space[0] -= range.Length();
  90.     SpaceTail( range.Start() ) << Tail( range.End() );
  91.   }
  92.  
  93. void PString::Insert( uint32 where, uint8 c )
  94.   {
  95.     Assert( Length() + 1 < StorageLength() );
  96.     Assert( where <= Length() );
  97.     
  98.     SpaceTail( where+1 ) << Tail( where );
  99.     (*this)[ where ] = c;
  100.     space[ 0 ]++;
  101.   }
  102.  
  103. void PString::Insert( uint32 where, ConstData text )
  104.   {
  105.     Assert( Length() + text.Length() < StorageLength() );
  106.     Assert( where <= Length() );
  107.     
  108.     SpaceTail( where + text.Length() ) << Tail( where );
  109.     SpaceTail( where ) << text;
  110.     space[ 0 ] += text.Length();
  111.   }
  112.  
  113. void PString::Replace( URange32 range, uint8 c )
  114.   {
  115.     Assert( range.End() <= Length() )
  116.     Assert( Length() - range.Length() + 1 < StorageLength() );
  117.     
  118.     SpaceTail( range.Start() + 1 ) << Tail( range.End() );
  119.     (*this)[ range.Start() ] = c;
  120.     space[ 0 ] -= range.Length();
  121.     space[ 0 ] ++;
  122.   }
  123.  
  124. void PString::Replace( URange32 range, ConstData text )
  125.   {
  126.     Assert( range.End() <= Length() )
  127.     Assert( Length() - range.Length() + text.Length() < StorageLength() );
  128.     
  129.     SpaceTail( range.Start() + text.Length() ) << Tail( range.End() );
  130.     SpaceTail( range.Start() ) << text;
  131.     space[ 0 ] -= range.Length();
  132.     space[ 0 ] += text.Length();
  133.   }
  134.